package com.cictec.middleware.tde.rm.protocol.rm.decode;

import java.nio.ByteBuffer;

import org.apache.mina.core.session.IoSession;

import com.cictec.middleware.commons.utils.BinaryUtils;
import com.cictec.middleware.tde.exception.MessageDecoderException;
import com.cictec.middleware.tde.rm.protocol.AbstractMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage.Header;
import com.cictec.middleware.tde.rm.protocol.annotion.TerminalMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.rm.message.Rm0x80PlatformMessage;
import com.cictec.middleware.tde.rm.protocol.rm.utils.RmBinaryUtils;

/**
 * 0x80 指令应答
 * 
 * @author ql
 *
 */
@TerminalMessageDecoder(0x80)
public class Rm0x80Decoder extends AbstractMessageDecoder {

//	private static Logger logger = LoggerFactory.getLogger(Rm0x80Decoder.class);
	
	@Override
	public TerminalMessage decode(Header header, ByteBuffer in, IoSession session) throws MessageDecoderException {

		Rm0x80PlatformMessage msg = new Rm0x80PlatformMessage(header);
		msg.setResponseTime(RmBinaryUtils.dwordToDateRM(in));
		msg.setResponseMessageId(BinaryUtils.unsignedByteToInt(in));
		msg.setResponseMessageSequence(BinaryUtils.unsignedByteToInt(in));
		msg.setResponseType(BinaryUtils.unsignedByteToInt(in));
		msg.setReserved(BinaryUtils.wordToInt(in));
		
//		logger.debug(JSON.toJSONString(msg));
		
		return msg;
	}

}
